package com.myzombieapocalypse.projectz.web;

import com.myzombieapocalypse.projectz.application.LoginFacade;
import com.myzombieapocalypse.projectz.domain.Account;
import com.myzombieapocalypse.projectz.web.forms.Login;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: StuartS
 * Date: 26/10/11
 * Time: 19:48
 */
public class LoginController extends SimpleFormController {
    private LoginFacade loginFacade;

    public void setLoginFacade(LoginFacade loginFacade) {
        this.loginFacade = loginFacade;
    }

    @Override
    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
        Login login = (Login) command;
        Account account = loginFacade.verifyLogin(login);
        return new ModelAndView(getSuccessView());
    }
}
